package com.gupao.jly521.apache.common;

import org.apache.commons.configuration.CompositeConfiguration;
import org.apache.commons.configuration.PropertiesConfiguration;

import javax.naming.ConfigurationException;

/**
 * @author Jly
 * @date 2018/9/3  8:45
 */
public class ConfigurationUsage {

    public static void main(String[] args) {

        String jdbcUrl = propManager.getInstance().getProperty("jdbc.cms.url");

        String jdbcUsername = propManager.getInstance().getProperty(

                "jdbc.cms.username");

        String jdbcPassword = propManager.getInstance().getProperty(

                "jdbc.cms.password");



        System.out.println("jdbcUrl:"+ jdbcUrl);

        System.out.println("jdbcUsername:"+ jdbcUsername);

        System.out.println("jdbcPassword:"+ jdbcPassword);



    }



    private ConfigurationUsage() {

    }



    private static ConfigurationUsage propManager;



    public synchronized static ConfigurationUsage getInstance() {

        if(propManager == null) {

            propManager= new ConfigurationUsage();

        }

        return propManager;

    }



    public static CompositeConfiguration config = new CompositeConfiguration();

    static{
        try {
            config.addConfiguration(new PropertiesConfiguration("db.properties"));
        } catch (org.apache.commons.configuration.ConfigurationException e) {
            e.printStackTrace();
        }
    }



    public String getProperty(String key) {

        return config.getString(key);

    }

}